package com.example.goodpet.community.fragment;

import android.content.Intent;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.TextView;

import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import com.example.goodpet.R;
import com.example.goodpet.activity.SearchActivity;
import com.example.goodpet.base.BaseFragment;
import com.example.goodpet.community.activity.ReleaseTieziActivity;
import com.example.goodpet.community.bean.UserTieziInfo;
import com.example.goodpet.utils.UIUtils;

public class CommunityFragment extends BaseFragment {
    private ImageButton community_search;
    private TextView community_release;
    private CommunityContent communityContent;
    @Override
    public View initView() {
        View view = UIUtils.getView(R.layout.fragment_community);

        community_search = view.findViewById(R.id.community_search);
        community_release = view.findViewById(R.id.community_release);

        FragmentManager childFragmentManager = getChildFragmentManager();
        FragmentTransaction transaction = childFragmentManager.beginTransaction();
        communityContent = new CommunityContent();
        transaction.replace(R.id.frame_layout,communityContent);
        transaction.commit();
        initListener();
        return view;
    }

    public void refresh(int position, UserTieziInfo info){
        this.communityContent.refresh(position,info);
    }
    private void initListener() {
        community_search.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //UIUtils.toast("搜索",false);
                Intent intent=new Intent(mContext, SearchActivity.class);
                intent.putExtra("type",2);
                mContext.startActivity(intent);
            }
        });
        community_release.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(mContext, ReleaseTieziActivity.class);
                mContext.startActivity(intent);
            }
        });
    }
}
